*This file creates Figure 1.

* Load the dataset and calculate the labor share from 1934-1939 in manufacturing
use "$path/industry_data.dta", clear
collapse (sum) Labor_all, by(digt2 year)
bys year: egen sum = sum(Labor_all)
gen share = Labor_all/sum
keep if year < 1939
collapse share, by(digt2)
egen sum2 = sum(share)

edit if digt2 == 36 | digt2 == 37 | digt2 == 38 | digt2 == 25 | digt2 == 27
rename digt2 isic2
drop sum2
tempfile temp
save `temp'

* Load dataset of reparations in aggregate industries and prepare for merging
*See paper for data sources
use "$path/occupation_reparation_data.dta", clear
gen isic2 = substr(digitindustrygroup, -3, 2)
destring isic2, replace
joinby isic2 using `temp', unmatched(master)
replace share = share * 100
gen digitindustrygroup2 = substr(digitindustrygroup, 1, length(digitindustrygroup) - 4)
replace digitindustrygroup2 = trim(digitindustrygroup2)
replace isic2 = 2 if isic2 == 25 | isic2 == 27
replace digitindustrygroup2 = "Wood and Paper" if isic2 == 2
replace isic2 = 99 if isic2 == 15 | isic2 == 31 | isic2 == 32 | isic2 == 33 | isic2 == 39 | isic2 == 34 | isic2 == 35
replace digitindustrygroup2 = "Other Manufacturing" if isic2 == 99
collapse (sum) reparationsallocated share laborsharetotal, by(isic2 digitindustrygroup2)
replace share = round(share, 0.01)
replace share = (100 - 38.62 - 5.76 - 1.25 - 4.63) if digitindustrygroup2 == "Other Manufacturing"
*Multiply the values by population share in manufacturing 14%
replace laborsharetotal = share * 0.14 if isic2 != 0

* Update industry group names
gen digitindustrygroup = digitindustrygroup2
replace digitindustrygroup = "Transport Equipment" if isic2 == 38
replace digitindustrygroup = "Electrical Machinery" if isic2 == 37
replace digitindustrygroup = "Machinery" if isic2 == 36
label var reparationsallocated "Reparations (%)"
label var share "Labor share within manufacturing (%)"
label var laborsharetotal "Total labor share (%)"
replace digitindustrygroup = "Agriculture" if isic2 == 0

* Create and export bar chart for reparations across aggregate sectors
graph bar (asis) reparationsallocated laborsharetotal share, over(digitindustrygroup, sort(isic2) label(angle(45))) plotregion(lcolor(white)) graphregion(lcolor(white) fcolor(white) color(white)) title("Panel B: Reparations Across Aggregate Sectors", size(4)) saving(bars.gph, replace) legend(order(1 "Reparations (%)" 2 "Total labor share (%)" 3 "Labor share within manufacturing (%)") position(6) textwidth(35) rows(2)) bar(1, color(red*0.7)) bar(2, color(dkgreen*0.9)) bar(3, color(navy*0.9))


* Export the graph to different formats
graph export "$graphs/descriptive_bars.eps", as(eps) font(Times) replace
graph export "$graphs/descriptive_bars.pdf", as(pdf) font(Times) replace

*Black and white

graph bar (asis) reparationsallocated laborsharetotal share, ///
    over(digitindustrygroup, sort(isic2) label(angle(45))) ///
    plotregion(lcolor(white)) ///
    graphregion(lcolor(white) fcolor(white) color(white)) ///
    title("Panel B: Reparations Across Aggregate Sectors", size(4)) ///
    saving(bars_bw.gph, replace) ///
    legend(order(1 "Reparations (%)" 2 "Total labor share (%)" 3 "Labor share within manufacturing (%)") ///
           position(6) textwidth(35) rows(2)) ///
    bar(1, color(gs0)) ///
    bar(2, color(gs10)) ///
    bar(3, color(gs14))

* Export the graph to different formats
graph export "$graphs/descriptive_bars_bw.eps", as(eps) font(Times) replace
graph export "$graphs/descriptive_bars_bw.pdf", as(pdf) font(Times) replace


*** Pie charts preparation ***

*Presenting Figures drawn from Auer (1956)

* Clear current data and set up the new dataset
clear
set obs 15

* Initialize the variables
gen name = .
gen value = .
gen export = .

* Assign values and names for the categories
replace value = 5 in 1
replace value = 33 in 2
replace value = 62 in 3
tostring name, replace
replace name = "Other Products" in 1
replace name = "Timber, wood and paper products" in 2
replace name = "Metal industry products" in 3

* Assign more values and names for additional categories
replace value = 14 in 4
replace value = 84 in 5
replace value = 2 in 6
tostring name, replace
replace name = "Other" in 4
replace name = "Timber, wood and paper products" in 5
replace name = "Metal industry products" in 6

* Continue assigning values and names for remaining categories
replace value = 53 in 7
replace value = 33 in 8
replace value = 14 in 9
replace name = "Manufacturing" in 10
replace name = "Agriculture & Forestry" in 11
replace name = "Services" in 12
replace value = 14 in 10
replace value = 60 in 11
replace value = 26 in 12

* Define the category indicator variable
gen ind = "War reparations"
replace ind = "Finnish Exports 1929-1938" in 4/6
replace ind = "Finnish Industrial Production 1943" in 7/9
replace ind = "Finnish Occupational Structure 1940" in 10/12

* Remove existing graphs and turn off graphic display
graph drop _all
set graphics off

* Create and save the first pie chart
graph pie value if ind == "War reparations", name(g1, replace) over(name) plabel(_all percent, size(large)) graphregion(margin(vlarge) fcolor(white) lcolor(white) color(white)) pie(2, color(gray*.1)) pie(3, color(navy*.9)) pie(1, color(maroon)) legend(margin(zero)) title("War Reparation Demands") legend(textwidth(35)) saving(pie1.gph, replace)

* Create and save the second pie chart
graph pie value if ind == "Finnish Exports 1929-1938", name(g2, replace) over(name) plabel(_all percent, size(large)) graphregion(margin(vlarge) fcolor(white) lcolor(white) color(white)) pie(2, color(gray*.2)) pie(3, color(navy*.9)) pie(1, color(maroon)) title("Finnish Exports 1929-1938") legend(off) saving(pie2.gph, replace)

* Combine two pie charts for a panel display
graph combine pie1.gph pie2.gph, col(2) iscale(0.7) commonscheme graphregion(margin(small) fcolor(white) lcolor(white) color(white)) plotregion(margin(small))
set graphics on

* Create a shared legend for the combined charts
grc1leg pie1.gph pie2.gph, legendfrom(pie1.gph) iscale(0.7) graphregion(fcolor(white) lcolor(white) color(white)) saving(pie_combined.gph, replace) title("Panel A: Demanded Reparations and Pre-War Exports", size(4))

* Export the combined charts
graph export "$graphs/twopies.eps", as(eps) font(Times) replace


*Black and white

* Create and save the first pie chart - War Reparations (Black and White)
graph pie value if ind == "War reparations", name(g1, replace) over(name) ///
    plabel(_all percent, size(large)) ///
    graphregion(margin(vlarge) fcolor(white) lcolor(white) color(white)) ///
    pie(1, color(gs10)) /// Using grayscale (gs0) for black-and-white
    pie(2, color(gs14)) /// Second slice with darker grayscale (gs10)
    pie(3, color(gs4)) /// Third slice with even darker grayscale (gs14)
    legend(margin(zero)) ///
    title("War Reparation Demands") ///
    legend(textwidth(35)) ///
    saving(pie1_bw.gph, replace) /// Save as black-and-white pie chart (pie1_bw.gph)

* Create and save the second pie chart - Finnish Exports 1929-1938 (Black and White)
graph pie value if ind == "Finnish Exports 1929-1938", name(g2, replace) over(name) ///
    plabel(_all percent, size(large)) ///
    graphregion(margin(vlarge) fcolor(white) lcolor(white) color(white)) ///
    pie(1, color(gs10)) /// Using grayscale (gs0) for black-and-white
    pie(2, color(gs14)) /// Second slice with darker grayscale (gs10)
    pie(3, color(gs4)) /// Third slice with even darker grayscale (gs14)
    title("Finnish Exports 1929-1938") ///
    legend(off) /// Turn off the legend for this pie chart
    saving(pie2_bw.gph, replace) /// Save as black-and-white pie chart (pie2_bw.gph)

* Combine two pie charts for a panel display
graph combine pie1_bw.gph pie2_bw.gph, col(2) iscale(0.7) commonscheme ///
    graphregion(margin(small) fcolor(white) lcolor(white) color(white)) ///
    plotregion(margin(small))

* Create a shared legend for the combined charts
grc1leg pie1_bw.gph pie2_bw.gph, legendfrom(pie1_bw.gph) iscale(0.7) ///
    graphregion(fcolor(white) lcolor(white) color(white)) ///
    saving(pie_combined_bw.gph, replace) ///
    title("Panel A: Demanded Reparations and Pre-War Exports", size(4))

* Export the combined charts as EPS for use in Overleaf or LaTeX
graph export "graphs/twopies_bw.eps", as(eps) font(Times) replace
graph export "$graphs/twopies_bw.pdf", as(pdf) font(Times) replace
